<template>
  <div class="wrapper">
    <v-head v-if="!innfullscreen" v-show="(!topmenuCollapse || topmenuTempshow)"></v-head>
      <v-sidebar v-if="!innfullscreen && !isbis"></v-sidebar>
      <vbis-sidebar v-if="!innfullscreen && isbis"></vbis-sidebar>
      <div :class="[{'content-collapse':collapse}, innfullscreen?'content-box-full':'content-box']" :style="{'top':(innfullscreen || topmenuCollapse)?'0':'35px','bottom':'25px'}">
          <v-tags v-if="!innfullscreen" ref="itemtags"></v-tags>
          <div class="content" ref="PageMainContent" id="PageMainContent">
              <!-- <transition mode="out-in" name="move"> -->
                  <keep-alive :include="tagsList">
                      <router-view :key="routekey"></router-view>
                  </keep-alive>
              <!-- </transition> -->
          </div>
      </div>
      <rm_BIS_View @afterCall="afterCall" ref="rmbisview"></rm_BIS_View>
      <v-pbottom></v-pbottom>
  </div>
</template>

<script>
import vHead from "./Header.vue";
import vSidebar from "./Sidebar.vue";
import vPbottom from "./Pbottom.vue";
import vbisSidebar from "./SidebarBis.vue";
import vTags from "./Tags.vue";
// import { close } from "fs";
export default {
  data() {
      return {
          tagsList: [],
          collapse: true,
          topmenuCollapse: false,
          topmenuTempshow: false,
          innfullscreen: false,
          isbis: false,
          items: [], //菜单数组
      };
  },
  components: {
      vHead,
      vSidebar,
      vTags,
      vbisSidebar,
    vPbottom
  },
  created() {
      var that = this;
      this.topmenuCollapse = this.$tool.getLocalConfig("topmenuCollapse") == "1";
      //  if(this.$route.query.u=="admin")
      if (this.$pub.innfullscreen == "1") {
          this.innfullscreen = true;
      }
      this.isbis = that.$tool.checkBis();
      if (this.isbis) {
          this.collapse = this.$tool.getLocalConfig("collapse") == "1";
      }

      window.addEventListener("resize", this.pagesizechanged);
      this.$bus.$on("routerchanged", (msg) => {
          this.pagesizechanged();
      });
      this.$bus.$on("collapse", (msg) => {
          this.collapse = msg;
      });
      this.$bus.$on("topmenuCollapse", (msg) => {
          this.topmenuCollapse = msg;
      });
      this.$bus.$on("topmenuMouseout", (msg) => {
          that.topmenuTempshow = false;
          document.onclick = null;
      });
      // this.$bus.$on("menuClick", (msg) => {
      //     if (!that.topmenuTempshow) {
      //         that.topmenuTempshow = true;
      //         that.$bus.$emit("topmenuTempshowing", true);
      //     }
      // });
      // 只有在标签页列表里的页面才使用keep-alive，即关闭标签之后就不保存到内存中了。
      this.$bus.$on("tags", (msg) => {
          let arr = [];
          for (let i = 0, len = msg.length; i < len; i++) {
              msg[i].name && arr.indexOf(msg[i].name) < 0 && arr.push(msg[i].name);
          }
          this.tagsList = arr;
          // console.log('tlist',this.tagsList);
      });

      this.$root.$el.onmousemove = function (e) {
          if (that.topmenuCollapse) {
              if (!that.topmenuTempshow) {
                  if (e.clientY < 6) {
                      if (!that.topmenuTempshow) {
                          that.topmenuTempshow = true;
                          // that.$bus.$emit("topmenuTempshowing", true);
                      }
                  }
              }
          }
      };
      this.$bus.$on("searchBIS", (no, no2, flag) => {
          that.eventSearchBIS(no, no2, flag);
      });

      this.$bus.$on("routerJump",(arg,pagecode,pagename)=>{
          if (this && this.$refs && this.$refs.itemtags) {
                  let index = this.$refs.itemtags.tagsList.findIndex((m) => m.name == pagecode);
                  this.$tool.setSession("currentmenu", pagecode + " " + pagename);
                  //console.log(index);
                  if (index >= 0) {
                      this.$router.push("/"+pagecode);
                      this.$bus.$emit("locateCondition", arg);
                  } else {
                      // console.log(2);
                      this.$router.push({
                          path:'/'+pagecode,
                          name: pagecode,
                          params: {
                              condition: arg,
                          },
                      });
                  }
              }
      })
  },
  computed: {
      routekey() {
          return this.$route.fullPath;
      },
  },
  methods: {
      pagesizechanged() {
          if (this && this.$refs && this.$refs.PageMainContent && this.$refs.PageMainContent.offsetHeight) {
              // console.log("pageMainContentHeight", this.$refs.PageMainContent.offsetHeight);
              this.$bus.$emit("pagesizeChanged", this.$refs.PageMainContent.offsetHeight);
          }
      },
      close(windowName) {
          if (this && this.$refs && this.$refs.itemtags) {
              let index = this.$refs.itemtags.tagsList.findIndex((m) => m.name == windowName);
              this.$refs.itemtags.tagsList.splice(index, 1);
          }
          this.$router.go(-1);
      },
      setSearchBoxFocus() {
          this.$bus.$emit("focusSearchBox", "ccc");
      },
      eventSearchBIS(no, no2, flag) {
          //this.$bus.$emit('searchBIS','12345','1')
          this.$refs.rmbisview.openView(no, flag, no2);
          //alert(flag==1?'血袋编号':(flag==2?'申请单号':(flag==3?'检验条码':'病历号')),no);
      },
      afterCall(flag, id) {
          console.log(flag);
          if (flag == 0) {
              this.setSearchBoxFocus();
          } else if (flag == 1) {
              if (this && this.$refs && this.$refs.itemtags) {
                  let index = this.$refs.itemtags.tagsList.findIndex((m) => m.name == "NBS510");
                  this.$tool.setSession("currentmenu", "NBS510" + " " + "用血日常综合管理");
                  //console.log(index);
                  if (index >= 0) {
                      this.$router.push("/NBS510");
                      this.$bus.$emit("locateOrder", id);
                  } else {
                      // console.log(2);
                      this.$router.push({
                          //path:'/NBS510',
                          name: "NBS510",
                          params: {
                              orderid: id,
                          },
                      });
                  }
              }
          }
      },
  },
  beforeDestroy() {
      this.$bus.$off("collapse");
      this.$bus.$off("routerchanged");
      this.$bus.$off("searchBIS");
      this.$bus.$off("tags");
      this.$bus.$off("topmenuCollapse");
      this.$bus.$off("topmenuMouseout");
      // this.$bus.$off("menuClick");
      window.removeEventListener("resize", this.pagesizechanged);
  },
};
</script>

<style scoped>
</style>
